A parameter is a value that is passed into a method when it is called.
Here is an example of a method that uses a parameter.
class CheckingAccount
{
. . . .
private int balance;
. . . .
void processDeposit( int amount )
{
balance = balance + amount ;
}
}
The parameter amount is used by a caller to send a
value to the method.
This is called passing a value into the method.
Here is part of a main() method that uses the parameter to
pass a value into the processDeposit() method:
class CheckingAccountTester
{
public static void main( String[] args )
{
CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );
bobsAccount.processDeposit( 200 );
// . . . . assume that more statements follow
}
}
When the statement
bobsAccount.processDeposit( 200 );
is executed,
the parameter amount of the object's method will hold
the value 200.
This value is added to the object's instance variable in the statement
balance = balance + amount ;
Then the method is finished and control returns to main().
The state of the object referred to by bobsAccount will have
been changed.
balance of the CheckingAccount object
hold a permanent value?amount of the object's processDeposit() method
hold a permanent value?